#include <iostream>
using namespace std;

bool isValidSequence(string sequence) {
    int stackSize = 0;
    
    for (char c : sequence) {
        if (c == '(' || c == '[' || c == '{' || c == '<') {
            stackSize++;
        } else if (c == ')' || c == ']' || c == '}' || c == '>') {
            if (stackSize == 0) {
                return false;
            }
            stackSize--;
        }
    }
    
    return stackSize == 0;
}

int main() {
    string sequence;
    cout << "Введите скобочную последовательность: ";
    getline(cin, sequence);
    cout << isValidSequence(sequence) << endl;
    return 0;
}
